package cci.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import cci.bdd.PersonneDB;
import cci.dao.DAOFactory;
import cci.pojo.Panier;

/**
 * Application Lifecycle Listener implementation class SessionListener
 *
 */
@WebListener
public class SessionListener implements HttpSessionListener {

    /**
     * Default constructor. 
     */
    public SessionListener() {
        // never used
    }

	/**
     * @see HttpSessionListener#sessionCreated(HttpSessionEvent)
     */
    public void sessionCreated(HttpSessionEvent arg0) {
        Panier panier = new Panier();
        arg0.getSession().setAttribute("panier", panier);
        
        PersonneDB personne = new PersonneDB();
        personne.setDatabase(DAOFactory.getPersonneDAO());
        arg0.getSession().setAttribute("personne", personne);
        
        
    }

	/**
     * @see HttpSessionListener#sessionDestroyed(HttpSessionEvent)
     */
    public void sessionDestroyed(HttpSessionEvent arg0) {
        arg0.getSession().removeAttribute("panier");
        arg0.getSession().removeAttribute("personne");
    }
	
}
